package com.vst.serverdatalib.https;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.vst.serverdatalib.R;


/**
 * @ClassName: NetWorkHelper
 * @Description: TODO(判断网络是否可用)
 * @author 武江南
 * @date 2014-7-7 上午11:14:46
 * 
 */
public class NetWorkHelper {
    
    /**
    * @Title: isNetworkAvailable 
    * @Description: TODO(判断设备是否有可使用的网络) 
    * @param @param context
    * @param @return    设定文件 
    * @return boolean    返回类型 
    * @throws
     */
    public static boolean isNetworkAvailable(Context context) {
        if (context == null) {
            return false;
        }
        ConnectivityManager connectivity = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity != null) {
            NetworkInfo[] info = connectivity.getAllNetworkInfo();
            if (info != null) {
                for (int i = 0; i < info.length; i++) {
                    if (info[i].isAvailable() && info[i].isConnected()) {
                        return true;
                    }
                }
            }
        }
        try {
            ToastUtil.show(context, R.string.net_error);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
}
